//https://dart.cn/language/#exceptions

/**
使用 throw 关键字抛出一个异常

使用 try 语句配合 on 或 catch（两者也可同时使用）关键字来捕获一个异常
 */

import 'dart:io';
import 'dart:async';
import 'my_mixins.dart';//导入Piloted

// 定义一个描述飞越对象的异步函数
Future<void> describeFlybyObjects(List<String> flybyObjects) async {
  try {
    for (final object in flybyObjects) {
      var file = File('$object.txt');
      if (await file.exists()) {
        var description = await file.readAsString();
        print(description);
      } else {
        print('No description file found for $object.');
      }
    }
  } on FileSystemException catch (e) {
    print('Could not describe object: $e');
  } finally {
    flybyObjects.clear();
  }
}

void main() async {
  var pilotedCraft = PilotedCraft('Apollo 11', DateTime(1969, 7, 16));

  pilotedCraft.checkAstronauts(); 

  var flybyObjects = ['Voyager I', 'Voyager II', 'Apollo 11', 'Hubble'];

  await describeFlybyObjects(flybyObjects);

  print('Description files reading process completed.');
}